using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BANSACH.BusinessLayer.DataLayer;
using BANSACH.BusinessLayer;
namespace BANSACH_GUI
{
    public partial class frmThamsohethongDm : FormBase
    {
        DataView data;
        ThamsohethongFactory objDao;
        Thamsohethong _entity;

        public Thamsohethong Entity
        {
            get { return _entity; }
            set { _entity = value; }
        }
        public frmThamsohethongDm()
        {
            InitializeComponent();
        }

        private void frmThamsohethongDm_Load(object sender, EventArgs e)
        {
            ConfigGrid();

            objDao = new ThamsohethongFactory();
            data = objDao.GetAll().DefaultView;
            grvData.DataSource = data;
        }
        private void ConfigGrid()
        {
            grvData.ModeColorRow = 1;
            grvData.SetColorRow(System.Drawing.Color.AliceBlue);

            
				grvData.AddColumns("TextBox","ma","ma",200,true,true,"ML","");
				grvData.AddColumns("TextBox","ten","ten",200,true,true,"ML","");
				grvData.AddColumns("TextBox","giatri","giatri",200,true,true,"ML","");
				grvData.AddColumns("TextBox","mota","mota",200,true,true,"ML","");
				grvData.AddColumns("TextBox","trienkhai","trienkhai",200,true,true,"ML","");
        }
        private void SetDataFilter()
        {
            try
            {
                StringBuilder filter = new StringBuilder("1=1");
                data.RowFilter = filter.ToString();
            }
            catch
            { }
        }

        private void grvData_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsLetter(e.KeyChar))
                ActiveControl = txt_Key;
        }

        private void grvData_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Apply();
        }

        private void grvData_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.Enter)
                Apply();
            if (e.Control)
                ActiveControl = grvData;
        }
        private void Apply()
        {
            _entity = new Thamsohethong();
            if (grvData.SelectedCells.Count == 0) return;
            int idrow = grvData.SelectedCells[0].RowIndex;
            this.DialogResult = DialogResult.OK;
        }
    }
}
